package com.kuang.design.creation.builder;

/**
 * 建造者模式
 * 建造者用XXbuilder类建造对象，在建造者类中完成对象各个属性的建造，
 * 建造者模式则是要求按照指定的蓝图（产品对象属性）建造产品，它的主要目的是通过组装零配件(一一设置对象属性的值)而产生一个新产品。
 */
public class MainTest {
    public static void main(String[] args) {
        AbstractBuilder xiaoMiBuilder = new XiaoMiBuilder();
        //1、建造手机，普通调用
        xiaoMiBuilder.customCpu("晓龙888");
        xiaoMiBuilder.customDisk("512G");
        xiaoMiBuilder.customCam("12000万");
        xiaoMiBuilder.customMem("16G");
        Phone phone = xiaoMiBuilder.getPhone();

        System.out.println("phone-" + phone);

        //2、链式调用
        AbstractLinkBuilder xiaoMiLinkBuilder = new XiaoMiLinkBuilder();
        AbstractLinkBuilder abstractLinkBuilder = xiaoMiLinkBuilder
                .customCpu("晓龙888")
                .customCam("15000万")
                .customDisk("1T")
                .customMem("16G");
        Phone phoneByLink = abstractLinkBuilder.getPhone();
        System.out.println("phoneByLink-" + phoneByLink);

        //Lombok @Builder注解调用
        PhoneWithBuilderPo.PhoneWithBuilderPoBuilder builder = PhoneWithBuilderPo.builder();
        PhoneWithBuilderPo phoneWithBuilder = builder
                .cam("12000")
                .cpu("cpu")
                .disk("2T")
                .mem("16G")
                .build();
        System.out.println("phoneWithBuilder-"+phoneWithBuilder);
    }
}
//0377-60320123